package com.sdhs.qualitymanage.controller;

import com.sdhs.common.annotation.Log;
import com.sdhs.common.core.controller.BaseController;
import com.sdhs.common.core.domain.AjaxResult;
import com.sdhs.common.core.page.TableDataInfo;
import com.sdhs.common.enums.BusinessType;
import com.sdhs.common.utils.poi.ExcelUtil;
import com.sdhs.qualitymanage.domain.GcQualityManagement;
import com.sdhs.qualitymanage.service.IGcQualityManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 质量管理Controller
 *
 * @author add
 * @date 2025-04-11
 */
@RestController
@RequestMapping("/quality/qualityManage")
public class GcQualityManagementController extends BaseController {
    @Autowired
    private IGcQualityManagementService gcQualityManagementService;

    /**
     * 查询清单管理树列表
     */
    @PreAuthorize("@ss.hasPermi('qualitymanage:qualitymanage:treeList')")
    @GetMapping("/treeList")
    public AjaxResult treeList(GcQualityManagement gcQualityManagement) {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("manageTreeList", gcQualityManagementService.selectManageListTreeList(gcQualityManagement));
        return ajax;
    }

    /**
     * 查询质量管理列表
     */
    @PreAuthorize("@ss.hasPermi('qualitymanage:qualitymanage:list')")
    @GetMapping("/list")
    public TableDataInfo list(GcQualityManagement gcQualityManagement) {
        startPage();
        List<GcQualityManagement> list = gcQualityManagementService.selectGcQualityManagementList(gcQualityManagement);
        return getDataTable(list);
    }

    /**
     * 导出质量管理列表
     */
    @PreAuthorize("@ss.hasPermi('qualitymanage:qualitymanage:export')")
    @Log(title = "质量管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GcQualityManagement gcQualityManagement) {
        List<GcQualityManagement> list = gcQualityManagementService.selectGcQualityManagementList(gcQualityManagement);
        ExcelUtil<GcQualityManagement> util = new ExcelUtil<GcQualityManagement>(GcQualityManagement.class);
        util.exportExcel(response, list, "质量管理数据");
    }

    /**
     * 获取质量管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('qualitymanage:qualitymanage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(gcQualityManagementService.selectGcQualityManagementById(id));
    }

    /**
     * 新增质量管理
     */
    @PreAuthorize("@ss.hasPermi('qualitymanage:qualitymanage:add')")
    @Log(title = "质量管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GcQualityManagement gcQualityManagement) {
        return toAjax(gcQualityManagementService.insertGcQualityManagement(gcQualityManagement));
    }

    /**
     * 修改质量管理
     */
    @PreAuthorize("@ss.hasPermi('qualitymanage:qualitymanage:edit')")
    @Log(title = "质量管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GcQualityManagement gcQualityManagement) {
        return toAjax(gcQualityManagementService.updateGcQualityManagement(gcQualityManagement));
    }

    /**
     * 删除质量管理
     */
    @PreAuthorize("@ss.hasPermi('qualitymanage:qualitymanage:remove')")
    @Log(title = "质量管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(gcQualityManagementService.deleteGcQualityManagementById(id));
    }
}
